package com.kang.controller;



import com.kang.aop.loginAop.SysLog;
import com.kang.entity.SysUser;
import com.kang.service.LoginService;
import com.kang.util.WebResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(tags = "用户登录退出接口")
@RestController
@RequestMapping("/admin/system/index")
@Slf4j
public class LoginController {

    @Autowired
    private LoginService loginService;


    @SysLog("查询登录")
    @ApiOperation("登录")
    @PostMapping("login")
    public WebResponse login(@RequestBody SysUser sysUser) {
        try {
            return WebResponse.resSuccess("登录成功",loginService.adminLogin(sysUser));
        } catch (Exception ex) {
            log.info("登录失败",ex);
            return WebResponse.resFail("登录失败",null);
        }
    }

    @ApiOperation("前端获取基本信息")
    @GetMapping("info")
    public WebResponse info(String token) {
        try {
            return WebResponse.resSuccess("前端获取基本信息成功",loginService.info(token));
        } catch (Exception ex) {
            log.info("前端获取基本信息失败",ex);
            return WebResponse.resFail("前端获取基本信息失败",null);
        }
    }

    @ApiOperation("退出")
    @PostMapping("logout")
    public WebResponse layout(@RequestBody String token) throws Exception {
        try {
            return WebResponse.resSuccess("退出成功",loginService.layout(token));
        } catch (Exception ex) {
            log.info("退出失败",ex);
            return WebResponse.resFail("退出失败",null);
        }
    }
}
